{% extends 'myhome/index.html' %}
{% block title %}
<title>天天生鲜-地址管理</title>
{% endblock %}
{% block main %}
	<div class="main_con clearfix">
		<div class="left_menu_con clearfix">
			<h3>用户中心</h3>
			<ul>
				<li><a href="{% url 'myhome_order_manage' %}" >· 个人信息</a></li>
				<li><a href="{% url 'myhome_order_order' %}" >· 全部订单</a></li>
				<li><a href="{% url 'myhome_order_addrIndex' %}" class="active">· 收货地址</a></li>
			</ul>
		</div>
		<div class="right_content clearfix">
				<h3 class="common_title2">收货地址</h3>
				<div class="site_con">
					<dl>
						<dt>当前地址：</dt>
						<dd>
						{{addr.shen}}&nbsp;&nbsp;{{addr.shi}}&nbsp;&nbsp;{{addr.xian}}&nbsp;&nbsp;{{addr.zhen}}&nbsp;&nbsp;{{addr.info}}&nbsp;({{addr.username}} 收)&nbsp;{{addr.phone}}
						</dd>
					</dl>					
				</div>
				<h3 class="common_title2">编辑地址</h3>
				<div class="site_con">
					<form id="addr" method="post" action="{% url 'myhome_address' %}">
					{% csrf_token %}
						<div class="form_group">
							<label>收件人：</label>
							<input type="text" name="username" value="{{addr.username}}">
						</div>
						<div>
							<select style="margin-left: 100px" class="shen aa" name="shen">
								<option>--请选择省--</option>
								{% for i in shen %}
								{% if i.name == addr.shen %}
								<option value="{{i.id}}" name="shu" selected>{{i.name}}</option>
								{% else %}
								<option value="{{i.id}}" name="shu">{{i.name}}</option>
								{% endif %}
								{% endfor %}
							</select>
							<select style="margin-left: 25px" class="shen bb" name="shi">
							 <option>--请选择--</option>
							</select>
							<select style="margin-left: 25px" class="shen cc" name="xian">
							 <option>--请选择--</option>
							</select>
							<select style="margin-left: 25px" name="zhen">
							 <option>--请选择--</option>
							</select>
						</div>
						<script type="text/javascript">
							$(".shen").change(function(){
								vals = $(this).val()
								el = $(this)
								$.get('{% url "myhome_citys" %}',{"id":vals},function(data){
									opt = "<option>--请选择--</option>"
									for(i in data){
										opt+="<option value="+data[i].id+">"+data[i].name+"</option>"
									}
									// 清空当前元素的下的所标签
									el.nextAll().empty()
									// 给默认样式
									el.nextAll().append("<option>--请选择--</option>")
									// 追加ajax返回的数据
									el.next().empty().append(opt)

								},'json')
							})
						</script>
						<div class="form_group form_group2">
							<label>详细地址：</label>
							<textarea class="site_area" name="info">{{addr.info}}</textarea>
						</div>
						<div class="form_group">
							<label>邮编：</label>
							<input type="text" name="code" value="{{addr.code}}">
						</div>
						<div class="form_group">
							<label>手机：</label>
							<input type="text" name="phone" value="{{addr.phone}}">
						</div>

						<input type="submit" value="提交" class="info_submit">
					</form>
				</div>
				<script type="text/javascript">
				
					$(".info_submit").click(function(){
						aa=($(".aa").val())
						bb=($(".bb").val())
						cc=($(".cc").val())
						username = $("input[name='username']").val()
						phone =  $("input[name='phone']").val()
						code = $("input[name='code']").val()
						info = $(".site_area").val()
						if (aa=="--请选择省--" || bb=="--请选择--" || cc=="--请选择--"|| username.length<2 || phone.length!=11||code.length<5||info==""){
							alert("请把资料填写完整")
							return false
						}
					})
				</script>
		</div>
	</div>
{% endblock %}